package com.sptpc.demo.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.Type;
import org.joda.money.Money;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
import java.util.List;

@Entity
@Table(name = "t_order")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Order {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer id; // 饮品编号

    @Column(updatable = false)
    @CreationTimestamp
    public LocalDate createTime; // 饮品名称

    @ManyToMany
    @JoinTable(name = "t_order_drink", joinColumns = {@JoinColumn(name = "drink_order_id")})
    @OrderBy("createTime")
    private List<Drink> items;

    private String customer;

    private Integer state;


    @NotNull
    @Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmount",
            parameters = {@org.hibernate.annotations.Parameter(name = "currencyCode", value = "CNY")})
    @NotNull
    public Money price;

}